    const moment = require('moment')
    const fs = require('fs')
    const path = require('path')
    const logger = (req, res, next) => {
    const ip = req.ip
    const time = moment().format('YYYY-MM-DD HH:mm:ss')
    const date = moment().format('YYYYMMDD')
    const method = req.method
    const url = req.url
    const agent = req.headers['user-agent']
    const text = `${ip} "${time}" "${method} - ${url}" "${agent}"\n`
    // console.log(text)
    const logPath = path.join(__dirname,'../logs',date+'.log')
    fs.appendFile(logPath,text,(err)=>{
        console.log(err)
    })
    next()
}

module.exports = logger